package de.hsowl.tod4a.global.model;

import java.util.HashMap;
import java.util.Set;

/**
 * Bean to store Class descriptions
 * 
 * @author Sebastian Witt
 * 
 */
public class SchemeMap {

	private HashMap<String, String> types = new HashMap<String, String>();
	private HashMap<String, String> kinds = new HashMap<String, String>();

	public SchemeMap() {
	}

	/**
	 * Adds a new attribute to the scheme
	 * 
	 * @param name - name of the member
	 * @param type - type (class name)
	 * @param kind - primitive or object or array
	 */
	public void addAttribute(String name, String type, String kind) {
		if (types.get(name) == null) {
			types.put(name, type);
			kinds.put(name, kind);
		}
	}

	public String getKind(String name) {
		return kinds.get(name);
	}

	public String getType(String name) {
		return types.get(name);
	}

	public Set<String> getAttributeNames() {
		return types.keySet();
	}

	/**
	 * Compares a Scheme to another
	 * 
	 * @param scheme
	 * @return true-identical<br>
	 *         false-different
	 */
	public boolean compareTo(SchemeMap scheme) {
		for (String attribute : scheme.getAttributeNames()) {
			if (getType(attribute) == null || getType(attribute).equals(scheme.getType(attribute)) == false) {
				return false;
			} else if (getKind(attribute) == null || getKind(attribute).equals(scheme.getKind(attribute)) == false) {
				return false;
			}
		}
		return true;
	}

	/**
	 * Compares a Scheme to an ObjectMap scheme
	 * 
	 * @param map
	 * @return true-identical<br>
	 *         false-different
	 */
	public boolean compareTo(ObjectMap map) {
		for (Field field : map.getFields()) {
			if (getType(field.name) == null || getType(field.name).equals(field.type) == false) {
				System.out.println("SCHEMA UNTERSCHIEDLICH");
				return false;
			} else if (getKind(field.name) == null || getKind(field.name).equals(field.kind) == false) {
				System.out.println("SCHEMA UNTERSCHIEDLICH");
				return false;
			}
		}
		return true;
	}
}
